﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tenebrous_Manor.GameElements
{
    static class RandomizedFurniture
    {
        static public Dictionary<Navigation.Room, Tuple<int, int>[]> random_furniture = new Dictionary<Navigation.Room, Tuple<int, int>[]>();
        static Random randomNumbers = new Random((int)DateTime.Now.Ticks);

        static private Queue<Tuple<int, int>> queue = new Queue<Tuple<int,int>>();

        static public void setRandomFurniture(ref int[,] map, Navigation.Room room)
        {
            if (room == Navigation.Room.JUNK_ROOM || room == Navigation.Room.KITCHEN)
                return;

            if (!random_furniture.ContainsKey(room))
            {
                int x, y;
                Tuple<int, int>[] temp = new Tuple<int,int>[GameConstants.NUM_RAND_FURNITURE];
                for (int i = 0; i <= temp.Length - 1; i++)
                {
                    do{
                        x = randomNumbers.Next(1, GameConstants.COL_COUNT -2);
                        y = randomNumbers.Next(1, GameConstants.ROW_COUNT -2);
                    }while(map[x,y] != 0 || isNextToDoor(ref map, x, y));

                    temp[i] = Tuple.Create(x, y);
                }

                random_furniture.Add(room, temp);
            }

            foreach (Tuple<int, int> coord in random_furniture[room])
            {
                map[coord.Item1, coord.Item2] = 1;
            }
        }

        static private bool isNextToDoor(ref int[,] map, int x, int y)
        {
            if (map[x - 1, y] == 2
                || map[x + 1, y] == 2
                || map[x, y - 1] == 2
                || map[x, y + 1] == 2
             )
                return true;

            return false;
        }


        static private bool hasPath(ref int[,] map, Tuple<int, int> current, Tuple<int, int> finish)
        {

            if (current == finish)
                return true;
            else if (queue.Contains(current))
                return false;
            else if (map[current.Item1, current.Item2] != 0)
                return false;
            else
            {

            }
            return false;
        }
    }
}
